package com.itheima.chapter12.anno;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Test {
    public static void main(String[] args) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException {
        Class<AnnoDemo> annoDemoClass = AnnoDemo.class;
        AnnoDemo anno = annoDemoClass.getConstructor().newInstance();
        //通过字节码对象，反射类中所有成员方法
        Method[] methods = annoDemoClass.getDeclaredMethods();
        //遍历数组，获取每一个成员方法
        for (Method method : methods) {
            System.out.println(method);
            //看方法上是否有注解@MyTest
            if (method.isAnnotationPresent(MyTest.class)){
                //执行方法
                method.invoke(anno);
            }
        }
    }
}
